package com.panopset.sf;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics2D;

import javax.swing.JPanel;
import javax.swing.JTextField;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;

/**
 *
 * @author Karl Dinwiddie
 *
 */
public final class TestApp extends App {

    /**
     * Injector.
     */
    public static final Injector I = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(App.class).toInstance(new TestApp());
            bind(Osgw.class).annotatedWith(AboutBoxOsgw.class).toInstance(
                    new Osgw(W, H) {

                        @Override
                        public void paintCycle(final Graphics2D g) {
                            g.setColor(Color.CYAN);
                            g.fillRect(0, 0, W, H);
                        }

                    });
        }

    });

    /**
     * About box osgw.
     */
    @Inject
    @AboutBoxOsgw
    private Osgw osgw;

    /**
     * 100.
     */
    private static final int W = 100;

    /**
     * 100.
     */
    private static final int H = 100;

    /**
     *
     * @param s
     *            not used.
     */
    public static void main(final String... s) {
        I.getInstance(App.class).show();
    }

    /**
     * 30 cols for test.
     */
    private static final int TEST_COLS = 30;

    @Override
    public JPanel createWindowComp(final Windoc w) {
        JPanel p = ComponentFactory.createPanel(new FlowLayout());
        JTextField ktf = ComponentFactory.createKeyedTextField(w, "x");
        ktf.setColumns(TEST_COLS);
        p.add(ktf);
        return p;
    }

    @Override
    public String getFaviconPath() {
        return App.PANOPSET_ICON_PATH;
    }

    @Override
    public Dimension getDefaultSize() {
        return new Dimension(App.DEFAULT_WIDTH, App.DEFAULT_HEIGHT);
    }

    @Override
    public PopupBox createAboutBox() {

        return new PopupBox() {

            @Override
            public Dimension createSize() {
                return new Dimension(W, H);
            }

            @Override
            public Component createComponent() {
                return osgw.getPanel();
            }

        };
    }

    @Override
    public Injector getInjector() {
        return I;
    }

    @Override
    public String getUserBaseDirectory() {
        return ".com.panopset";
    }
}
